package org.evs.odesk.programmingSkills;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Locale;

/**
 * 
 * @author Dmitry Kalachov
 *         Write a program which will take the year (yyyy) and the numeric sequence of the month (0-11) as its input.
 *         The program will return the day on which the 28th of that particular month and year falls. The input can
 *         consist of two year-month combinations, one combination per line.
 * 
 *         The numeric sequence of months is as follows:
 * 
 *         0 – Jan
 *         1 – Feb
 *         2 – March
 *         and so on......
 * 
 *         The format for supplying the input is:
 * 
 *         1999-5
 * 
 *         Where 1999 is the year and 5 is the numeric sequence of the month (corresponding to June). The program should
 *         display the day on which June 28, 1999 fell, and in this case the output will be MONDAY.
 * 
 *         The output should be displayed in uppercase letters.
 * 
 *         Suppose the following INPUT sequence is given to the program:
 * 
 *         1999-5
 *         1998-6
 * 
 *         Then the output should be:
 * 
 *         MONDAY
 *         TUESDAY
 */
public class Task_28day {

    
    public static void main(String[] args) throws IOException, ParseException {
        BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
        String firstLine = consoleReader.readLine();
        String secondLine = consoleReader.readLine();

        String[] firstLineArray = firstLine.trim().split("-");
        String[] secondLineArray = secondLine.trim().split("-");

        int firstYear = Integer.parseInt(firstLineArray[0].trim());
        int firstMonth = Integer.parseInt(firstLineArray[1].trim());

        int secondYear = Integer.parseInt(secondLineArray[0].trim());
        int secondMonth = Integer.parseInt(secondLineArray[1].trim());

        String nameOfDay1 = getDayOfWeek(firstYear, firstMonth);
        String nameOfDay2 = getDayOfWeek(secondYear, secondMonth);

        System.out.println(nameOfDay1);
        System.out.println(nameOfDay2);
    }

    private static String getDayOfWeek(int year, int month) {
        DateFormatSymbols dfs = new DateFormatSymbols(Locale.ENGLISH);
        String weekdays[] = dfs.getWeekdays();

        Calendar firstCalendar = Calendar.getInstance();
        firstCalendar.set(year, month, 28);
        int day1 = firstCalendar.get(Calendar.DAY_OF_WEEK);
        String nameOfDay = weekdays[day1];
        return nameOfDay.toUpperCase();
    }
}
